/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;

/**
 *
 * @author petiano
 */
public class Desenho2D extends JPanel {

    List<Point> pontos;
    private final float proporcao  = 0.5f;

    public Desenho2D() {

        this.setVisible(true);
        pontos = new ArrayList<Point>();
    }

    public void desenhaObstaculo(Point p) {
        pontos.add(p);
        repaint();
    }

    public void desenhaGrade(Graphics g){
              //   Desenha grade
        float distDiv = 40 * proporcao;
        int numX = (int) Math.floor(this.getWidth() / distDiv);
        int numY = (int) Math.floor(this.getHeight() / distDiv);

        g.setColor(Color.LIGHT_GRAY);

        for(int i = 1; i <= numX; i++)
            g.drawLine((int)(i * distDiv), 0, (int)(i * distDiv), this.getHeight());
        for(int i = 1; i <= numY; i++)
            g.drawLine(0, (int)(i * distDiv), this.getWidth(), (int)(i * distDiv));
    }

    @Override
    /**
     * Este metodo desenha uma matriz 40 X 40 no Painel;
     */
    public void paint(Graphics g) {

        super.paint(g);
        desenhaGrade(g);

        for (int i = 0; i < pontos.size(); i++) {
            g.setColor(Color.BLUE);
            g.fillRect(pontos.get(i).x, pontos.get(i).y, 30, 30);
        }
    }
}
